from loguru import logger
from selenium import webdriver
from selenium.webdriver.common.by import By

from commonDemo.common_element import BaseAction


class Login(BaseAction):
    url = 'http://192.168.16.51/asmart/login/?state=http%3A%2F%2F192.168.16.51%2Fasmart%2Fasmart%2F%23%2Fmonitor%2Farea'
    username_loc = By.ID, 'username'
    password_loc = By.ID, 'password'
    button_denglu = "//button/span[text()='登 录']"
    sbmit_loc = By.XPATH, button_denglu

    def loginAmsart(self):
        # chrome_options = webdriver.ChromeOptions()
        # chrome_options.add_argument("lang=zh-CN.UTF-8")
        # self.driver = webdriver.Remote(command_executor="http://192.168.16.32:5444/wd/hub",
        #                                options=chrome_options
        #                                )
        self.driver.implicitly_wait(3)
        # 打开网址
        self.driver.get(self.url)
        # 输入用户名、密码
        self.input(self.username_loc, "tongyao")
        self.input(self.password_loc,"Asmart@123456789")
        logger.info("已输入用户名和密码")
        self.click(self.sbmit_loc)
        logger.info("已点击登录按钮")



